package com.dragon.common.modules.uaa.web.models.params;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

import java.io.Serializable;

/**
 * @author Chris Chan
 * Create On 2025/7/29 下午7:58
 * Use for:
 * Explain:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "用户名密码注册参数")
public class RegisterByUsernamePasswordParam implements Serializable {
    @NotBlank(message = "用户名不能为空")
    @Length(min = 6, max = 20, message = "用户名长度必须在6-20位之间")
    @Schema(description = "用户名", example = "admin")
    private String username;

    @NotBlank(message = "密码不能为空")
    @Length(min = 6, max = 20, message = "密码长度必须在6-20位之间")
    @Schema(description = "密码", example = "123456")
    private String password;

    @NotBlank(message = "确认密码不能为空")
    @Size(min = 6, max = 20, message = "密码长度必须在6-20位之间")
    @Schema(description = "确认密码", example = "123456")
    private String confirmPassword;
    // 验证码
    @NotBlank(message = "验证码不能为空")
    @Schema(description = "图形验证码", example = "1234")
    private String verifyCode;

    public static RegisterByUsernamePasswordParam create(String username, String password, String confirmPassword, String verifyCode) {
        return new RegisterByUsernamePasswordParam(username, password, confirmPassword, verifyCode);
    }

    public static RegisterByUsernamePasswordParam of(String username, String password, String confirmPassword, String verifyCode) {
        return new RegisterByUsernamePasswordParam(username, password, confirmPassword, verifyCode);
    }

    /**
     * 校验密码和确认密码是否一致
     * 多字段联合校验
     *
     * @return
     */
    @AssertTrue(message = "密码和确认密码不一致")
    public boolean isPasswordMatch() {
        return this.password.equals(this.confirmPassword);
    }
}
